import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'

// 表单校验
export const rules = reactive({
  appDsgnId: [required],
  content: [required],
  mode: [required],
})

// CrudSchema https://doc.iocoder.cn/vue3/crud-schema/
const crudSchemas = reactive<CrudSchema[]>([
  {
    label: '主键ID',
    field: 'id',
    isForm: false,
  },
  {
    label: '表单标题',
    field: 'title',
    isSearch: true,
  },
  {
    label: '流程应用ID',
    field: 'appDsgnId',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '初始版本',
    field: 'resId',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '发布状态',
    field: 'state',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '内容',
    field: 'content',
    isSearch: true,
    form: {
      component: 'Editor',
      componentProps: {
        valueHtml: '',
        height: 200
      }
    },
  },
  {
    label: '流程类型(0:简单流程;1:复杂流程;2:...)',
    field: 'mode',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '创建时间',
    field: 'createTime',
    formatter: dateFormatter,
    isSearch: true,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
    isForm: false,
  },
  {
    label: '版本',
    field: 'version',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '创建部门',
    field: 'createDept',
    isSearch: true,
    form: {
      component: 'InputNumber',
      value: 0
    },
  },
  {
    label: '状态',
    field: 'status',
    isSearch: true,
    form: {
      component: 'Radio'
    },
  },
  {
    label: '版本更新说明',
    field: 'remark',
    isSearch: true,
  },
  {
    label: '操作',
    field: 'action',
    isForm: false
  }
])
export const { allSchemas } = useCrudSchemas(crudSchemas)